<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>163-P215-作业-4</title>
</head>

<body>
    <!-- 4.开关灯案例 -->
    <button>开关灯</button>
    <script>
        var btn = document.querySelector('button');
        var isOpen = false;
        btn.onclick = function () {
            if (isOpen) {
                document.body.style.background = 'white';
                isOpen = false;
            } else {
                document.body.style.background = 'black';
                isOpen = true;
            }
        }
    </script>
</body>

</html>